//
//  GWMyTabBar.m
//  百思不得姐
//
//  Created by qianfeng on 16/3/1.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWMyTabBar.h"
#import "GWPublishViewController.h"
@interface GWMyTabBar ()
@property (nonatomic,weak)UIButton *plusBtn;
@end
@implementation GWMyTabBar

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
        UIButton *plusBtn =[[UIButton alloc]init];
        [plusBtn setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [plusBtn setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [plusBtn addTarget:self action:@selector(pushPublishView) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:plusBtn];
        self.plusBtn =plusBtn;
    }
    return self;
}
-(void)pushPublishView
{
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:[[GWPublishViewController alloc]init] animated:NO completion:nil];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat btnW =self.width/5;
    CGFloat btnH =self.height;
    CGFloat btnY =0;
    NSInteger j =0;
    for (UIView *btn in self.subviews) {
        
        if(![btn isKindOfClass:NSClassFromString(@"UITabBarButton")])continue;
        
        CGFloat btnX =btnW *(j>1?j+1:j);
        btn.frame =CGRectMake(btnX, btnY, btnW, btnH);
        j++;
    }
    
    self.plusBtn.size =self.plusBtn.currentImage.size;
    self.plusBtn.center =CGPointMake(self.width*0.5, self.height*0.5);
}
@end
